package win.smartown.android.scrollPagerDemo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import win.smartown.android.scrollPager.ScrollPager

class MainActivity : AppCompatActivity(), ScrollPager.OnPagerChangedListener, ScrollPager.OnScrollListener {

    val scrollPager by lazy { findViewById(R.id.pager) as ScrollPager }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        scrollPager.onPagerChangedListener = this
        scrollPager.onScrollListener = this
        showScrollDistance(0)
        showPageIndex()
    }

    override fun onScroll(scrollPager: ScrollPager, distance: Int) {
        showScrollDistance(distance)
    }

    override fun onPagerChanged(scrollPager: ScrollPager, position: Int) {
        showPageIndex()
    }

    fun showScrollDistance(distance: Int) {
        (findViewById(R.id.distance) as TextView).text = "$distance"
    }

    fun showPageIndex() {
        (findViewById(R.id.index) as TextView).text = "${scrollPager.currentChildIndex + 1}/${scrollPager.childCount}"
    }

}
